﻿using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Furion.CMS.Application
{
    /// <summary>
    /// 时间区域转换
    /// <para>
    /// 针对DateTimeOffset格式进行了本地化时区转换处理
    /// </para>
    /// </summary>
    public class DateTimeZoneConverter : Newtonsoft.Json.Converters.IsoDateTimeConverter
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public DateTimeZoneConverter()
        {
            DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value is DateTimeOffset utc)
            {
                value = utc.ToLocalTime();
            }
            base.WriteJson(writer, value, serializer);
        }
    }
}
